import { Button, Tabs } from "antd";
import Link from "next/link";
import { articleControllerFindAllArticle } from "@/app/servers/api/article";
import ArticleList from "./list";
import { cookies } from "next/headers";

export default async function CommunityPage() {
  const { data: articles } = await articleControllerFindAllArticle();
  const cookie = cookies().get("token");
  console.log(cookie);
  
  return (
    <div className="container mx-auto px-4 py-8">
      <div className="flex justify-between items-center mb-6">
        <h1 className="text-2xl font-bold">社区</h1>
        {cookie && (
          <Link href="/customer/community/create">
            <Button type="primary">发布文章</Button>
          </Link>
        )}
      </div>
      <Tabs
        key="1"
        items={[
          {
            label: "最新文章",
            tabKey: "1",
            key: "1",
            children: <ArticleList articles={articles} />,
          },
        ]}
      />
    </div>
  );
}
